/* eslint-disable array-callback-return */
import React, { Component } from "react";
import axios from "../../../http/request";

class feedback extends Component {
  state = {
    datas: [],
    level_one: [],
  };
  handleClick = () => {
    axios.get("home/relations/tsfkfl_h5?ignore_cache=1").then((res) => {
      console.log(res.data);
      this.setState({
        datas: res.data,
      });
    });
  };
  chooseGrade(id) {
    let newDatas = this.state.datas.filter((item) => {
      if (item.id === id) {
        return item;
      }
    });
    this.setState({
      level_one: [],
    });
    let newArr = [];
    newDatas[0].trees.slice(1).map((item) => {
      newArr.push(item);
      this.setState({
        level_one: newArr,
      });
    });
    console.log(this.state.level_one);
  }
  render() {
    return (
      <div>
        <button onClick={this.handleClick}>点击</button>
        <br />
        {this.state.datas.map((item) => {
          return (
            <button
              onClick={() => {
                this.chooseGrade(item.id);
              }}
              key={item.id}
            >
              {item.name}
            </button>
          );
        })}
        <br />
        {this.state.level_one.map((item) => {
          return <button key={item.id}>{item.name}</button>;
        })}
        <br />
      </div>
    );
  }
}

export default feedback;
